package com.liao.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.liao.dao.StudentDao;

import com.liao.util.Result;

@RestController
public class StudentController {
     @Autowired
     StudentDao stu;
     @RequestMapping("/getAllStu")
     @ResponseBody
     public Object getllStu(@RequestParam Map<String, Object> map) {
			 
    	 Integer page = Integer.parseInt(map.get("page").toString());
 		Integer limit = Integer.parseInt(map.get("limit").toString());
 		
 		map.put("page", (page - 1) * limit);
 		map.put("limit", limit);
 		List<Map<String, Object>> stduent = stu.getAllStu(map);

 		int count = stu.getCount();// 获取总条数
 		Result res = new Result("0", "true", count, stduent);
 		return res;
     }
     @RequestMapping("/inserts")
     @ResponseBody
     public Object inserts(@RequestParam Map<String, Object> map) {
    	 Result res =new Result("0","true",stu.inserts(map),"添加成功");
    	 return res;    
     }
     @RequestMapping("/update")
     @ResponseBody
     public Object update(@RequestParam Map<String, Object> map) {
    	 Result res =new Result("0","true",stu.update(map),"修改成功");
    	 return res; 
     }
     @RequestMapping("/del")
     @ResponseBody
     public Object del( int id) {
    	 Result res =new Result("0","true",stu.deletes(id),"删除成功");
    	 return res; 
     }
}
